package com.sgb.jicai.view.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sgb.jicai.BR;
import com.sgb.jicai.R;
import com.sgb.jicai.databinding.ItemJcChanceBinding;
import com.sgb.jicai.entity.JcChanceEntity;
import com.sgb.jicai.view.activity.JcChanceListActivity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

/**
 * 集采
 * 报价机遇、加盟机遇列表
 */
public class JcChanceAdapter extends BaseRecycleAdapter<JcChanceEntity> {
    private final int types;
    private ItemClickCallBack itemCallBack;
    public JcChanceAdapter(JcChanceListActivity context, int type, List<JcChanceEntity> datas) {
        super(context, R.layout.item_jc_chance, datas);
        this.context = context;
        types = type;
    }
    @Override
    public void convert(ItemViewHolder holder, JcChanceEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        ItemJcChanceBinding binding = (ItemJcChanceBinding) holder.getmBinding();
        binding.getRoot().setOnClickListener((v) -> {
            itemCallBack.onItemClick(entity);
        });
        entity.setType(types);
        binding.setViewModel(entity);
        updateButtonByStatusType(binding.tvStatus,binding.centralizedProcurementMethod, entity);
    }


    private void updateButtonByStatusType(TextView tvStatus, TextView centralizedProcurementMethod,JcChanceEntity entity) {
        switch (entity.getStatus()) {
            case 2://集采完成
            case 4://集采失败
                tvStatus.setText("已结束");
                tvStatus.setBackgroundResource(R.drawable.shape_graw_new_button);
//                tvStatus.setClickable(false);
                break;
            case 1://集采中
                if (entity.getType() == 1) {// 1 报价机遇
                    tvStatus.setText("我要报价");
                } else if (entity.getType() == 2) {//2 加盟机遇
                    tvStatus.setText("我要加盟");
                }
                tvStatus.setBackgroundResource(R.drawable.shape_blue_button);
//                tvStatus.setClickable(true);
                break;
            case 5://加盟中
                if (entity.getType() == 1) {// 1 报价机遇
                    tvStatus.setText("未开始");
                    tvStatus.setBackgroundResource(R.drawable.shape_graw_new_button);
//                    tvStatus.setClickable(false);
                } else if (entity.getType() == 2) {//2 加盟机遇
                    tvStatus.setText("我要加盟");
                    tvStatus.setBackgroundResource(R.drawable.shape_blue_button);
//                    tvStatus.setClickable(true);
                }
                break;
            case 6://报价中：
                if (entity.getType() == 1) {// 1 报价机遇
                    tvStatus.setText("我要报价");
                    tvStatus.setBackgroundResource(R.drawable.shape_blue_button);
//                    tvStatus.setClickable(true);
                } else if (entity.getType() == 2) {//2 加盟机遇
                    tvStatus.setText("已结束");
                    tvStatus.setBackgroundResource(R.drawable.shape_graw_new_button);
//                    tvStatus.setClickable(false);
                }
                break;
        }
        if (entity.getGroupBuyType().equals("0")){
            centralizedProcurementMethod.setText("------");
        }
    }

    public void setItemClickCallBack(ItemClickCallBack itemCallBack) {
        this.itemCallBack = itemCallBack;
    }

    public interface ItemClickCallBack {
        void onItemClick(JcChanceEntity entity);
    }
}
